﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bootstrap5.Design;

internal class DisplayDecoratorProvider : BreakPointClassDecoratorProvider<DisplayType,BreakingPointModel,IDisplayDecorator>, IDisplayDecorator
{

    public IDisplayDecorator None => GetKey(DisplayType.None);

    public IDisplayDecorator Block => GetKey(DisplayType.Block);

    public IDisplayDecorator Inline => GetKey(DisplayType.Inline);

    public IDisplayDecorator InlineBlock => GetKey(DisplayType.InlineBlock);

    public IDisplayDecorator Table => GetKey(DisplayType.Table);

    public IDisplayDecorator TableCell => GetKey(DisplayType.TableCell);

    public IDisplayDecorator TableRow => GetKey(DisplayType.TableRow);

    public IDisplayDecorator Grid => GetKey(DisplayType.Grid);

    public IDisplayDecorator Flex => GetKey(DisplayType.Flex);

    public IDisplayDecorator InlineFlex => GetKey(DisplayType.InlineFlex);

    protected override IDisplayDecorator GetKey(DisplayType type)
    {
        SetKey(type);
        return this;
    }

    protected override IDisplayDecorator GetBreakPoint(BreakPoint breakPoint)
    {
        SetBreakPoint(breakPoint);
        return this;
    }

    protected override void BuildClass()
    {
        Rules.AddRange(RuleDic.Select(m => GetCssClass(m.Key, m.Value)));
    }

    string GetCssClass(DisplayType type, IEnumerable<BreakingPointModel> values)
    {
        return string.Join(" ", values.Select(m => GetCssClass(type, m.BreakPoint)));
    }

    string GetCssClass(DisplayType type, BreakPoint? breakingPoint)
    {
        var builder = new StringBuilder("d");
        builder.Append(CssClassHelper.STRIPER);
        builder.Append(GetBreakPointString(breakingPoint));
        builder.Append(type.GetEnumCssClass());
        return builder.ToString();
    }
}
